<?php

//require_once('include/Gruper/Owner.php');
//$owner = new Owner();
//$owner->checkAccountsOwner();

//return;
require_once('modules/Dashboard/Activity.php');
global $mod_strings, $current_user;

$smarty = new Sugar_Smarty();

if(isset($_POST['from']) && isset($_POST['to'])){
    $from = $_POST['from'];
    $to = $_POST['to'];
}else{
    $from = date('Y-m').'-01';
    $to = date('Y-m-t');

}

if(isset($_POST['activityType'])){
    $type = $_POST['activityType'];
}else{
    $type = 'city';
}
$act = new Activity($type);
$access = $act->hasUserAccessToActivity($current_user->id);

if(is_admin($current_user) || $access){

$act->noServiceLabel = $mod_strings['LBL_NO_SERVICE'];
$act->from = $from;
$act->to = $to;

$cities = $act->getCities();
$months = $act->createMonthsArr($from, $to);
$cityUser = $act->getUserCities();
$data = $act->createData($from, $to);
$cityData = $act->getCitySummaryData();
$citySumData = $act->getCitySummarySum();
$summaryData = $act->getMonthData();
$userSummaryData = $act->getUserCitySummaryData();

$smarty->assign('cities', $cities);
$smarty->assign('months', $months);
$smarty->assign('cityUser', $cityUser);
$smarty->assign('data', $data);
$smarty->assign('cityData', $cityData);
$smarty->assign('citySumData', $citySumData);
$smarty->assign('summaryData', $summaryData);
$smarty->assign('userSummaryData', $userSummaryData);
$smarty->assign('allMC', $act->allMC);
$smarty->assign('allO', $act->allO);
$smarty->assign('collspan', $act->collspan * 4 + 3);

$smarty->assign('type', $type);
$smarty->assign('from', $from);
$smarty->assign('to', $to);
$smarty->assign('displayReportsType', true);
$smarty->assign('modStrings', $mod_strings);
echo $smarty->fetch('modules/Dashboard/activities.tpl');


}

